﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace Chapter02_Lesson02
{
    class Program
    {
        static void Main(string[] args)
        {
            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            for (int i = 0; i < 10000000; i++)
            {
                sw.WriteLine("Hello World" + i);
            }

            sw.Flush();

            ms.WriteTo(File.Create("memory.txt"));

            sw.Close();
            ms.Close();

            GZipStream gzOut = new GZipStream(File.Create("data.txt"), CompressionMode.Compress);
            StreamWriter sw2 = new StreamWriter(gzOut);

            for (int i = 0; i < 10000000; i++)
            {
                sw2.WriteLine("Hello World" +i);
            }

            sw2.Flush();

            sw2.Close();
            gzOut.Close();

            GZipStream gzIn = new GZipStream(File.OpenRead("data.txt"), CompressionMode.Decompress);
            StreamReader sr = new StreamReader(gzIn);

            sr.Close();
            gzIn.Close();

            //generating some tests, I guess that the taxe of compression is around 6 times...
        }
    }
}
